﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbSessionTest and is intended
    ///     to contain all TmdbSessionTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbSessionTest
    {
        /// <summary>
        ///     A test for TmdbSession Constructor
        /// </summary>
        [TestMethod]
        public void TmdbSessionConstructorTest()
        {
            var target = new TmdbSession();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for SessionId
        /// </summary>
        [TestMethod]
        public void SessionIdTest()
        {
            var target = new TmdbSession();
            string expected = Guid.NewGuid().ToString();
            target.SessionId = expected;
            string actual = target.SessionId;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Success
        /// </summary>
        [TestMethod]
        public void SuccessTest()
        {
            var target = new TmdbSession();
            bool expected = new Random().Next( 0, Int32.MaxValue ) % 2 == 0;
            target.Success = expected;
            bool actual = target.Success;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\session.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbSession();
            var jsonContent = File.ReadAllText( "session.json.txt" );
            var actual = await target.DeserializeJson<TmdbSession>( jsonContent );

            Assert.AreEqual( true, actual.Success );
            Assert.AreEqual( "80b2bf99520cd795ff54e31af97917bc9e3a7c8c", actual.SessionId );
        }
    }
}